<?php

namespace App\Http\Requests;

use App\User\User;
use http\Env\Request;
use Illuminate\Foundation\Http\FormRequest;

class ChangePasswordRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        $res = User::find($this->route('user')->id);
        return $res && $this->user()->can('update', $res);
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'oldpass'  => 'required',
            'password' => 'required|min:6|confirmed',
        ];
    }

    public function messages()
    {
        return [
            'oldpass.required' => '原始密码不能为空',
            'password.required'     => '新始密码不能为空',
            'password.min'          => '新密码不能少于6个字符',
            'password.confirmed'    => '两次输入新密码不一致',
        ];
    }

}
